package com.android.client.view.panel;

import java.util.ArrayList;

import com.android.server.util.Configration;
import com.google.gwt.event.dom.client.ChangeEvent;
import com.google.gwt.event.dom.client.ChangeHandler;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.ListBox;
import com.google.gwt.user.client.ui.Panel;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;

public class EditUIPanel extends VerticalPanel implements ChangeHandler{
	private static final String RESOLUSION_ARRAY = "resolution.array";
	private static final String PAGE_KEY = "page.size";
	private static final String RESOLUTION_TITLE = "Resolution";
	private static final String PAGE_TITLE = "Page";
	private VerticalPanel _resolutionPanel;
	private ListBox _resolutionSelect;
	private TextBox _R_text1;
	private TextBox _R_text2;
	private ListBox _pageSelect;
	private Panel _childPanel;
	private Configration _conf = Configration.getInstance();

	public EditUIPanel() {
		add(initResolusion());
		add(initPageSelection());
	}



	private ListBox initPageSelection() {
		_pageSelect = new ListBox();
		_pageSelect.setTitle(PAGE_TITLE);
		int pageCount = _conf.getInt(PAGE_KEY);
		
		return _pageSelect;
	}
	
	

	private VerticalPanel initResolusion() {
		String[] resolutions = _conf.getArray(RESOLUSION_ARRAY);
		_resolutionPanel = new VerticalPanel();
		_resolutionSelect = new ListBox();
		_resolutionSelect.setTitle(RESOLUTION_TITLE);
		for (int i = 0; i < resolutions.length; i++) {
			_resolutionSelect.setItemText(i, resolutions[i]);
		}
		_resolutionSelect.setItemText(resolutions.length, "others");
		_resolutionSelect.addChangeHandler(this);
		
		HorizontalPanel textPanel = new HorizontalPanel();
		_R_text1 = new TextBox();
		Label label = new Label();
		_R_text2 = new TextBox();
		textPanel.add(_R_text1);
		textPanel.add(label);
		textPanel.add(_R_text2);
		
		_resolutionPanel.add(_resolutionSelect);
		_resolutionPanel.add(textPanel);
		
		return _resolutionPanel;
	}

	@Override
	public void onChange(ChangeEvent event) {
		ListBox tempSelection = (ListBox) event.getSource();
		int count = tempSelection.getItemCount();
		int selectedIndex = tempSelection.getSelectedIndex();
		if(selectedIndex == (count -1)){
			
		}
	}

}
